package com.shop.controller;

import com.shop.base.BaseController;
import com.shop.entity.UserBehavior;
import com.shop.result.ResultVO;
import com.shop.service.UserBehaviorService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @author XCH
 * @date 2025 - 06 - 24
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/behavior")
public class UserBehaviorController extends BaseController {
    private final UserBehaviorService userBehaviorService;
    @GetMapping("/listUserBehavior")
    public ResultVO<List<UserBehavior>> listUserBehavior(@RequestParam("userId")Integer userId){
        List<UserBehavior> userBehaviorList = userBehaviorService.getUserBehaviorByUserId(userId);
        return success(200, "获取用户行为成功", userBehaviorList);
    }
    @GetMapping("/listProductIdAndActionType")
    public ResultVO<List<UserBehavior>> listProductIdAndActionType(@RequestParam("productId")Integer productId, @RequestParam("userId")Integer userId){
        List<UserBehavior> userBehaviorList = userBehaviorService.getProductIdAndActionType(productId, userId);
        return success(200, "获取商品行为成功", userBehaviorList);
    }
    @PostMapping("/addUserBehavior")
    public ResultVO<Integer> addUserBehavior(@RequestParam("userId") Integer userId, @RequestParam("productId")Integer productId, @RequestParam("actionType")String actionType, @RequestParam("createTime")String createTime){
        userBehaviorService.addUserBehavior(userId, productId, actionType, createTime);
        return success(200, "添加用户行为成功", 1);
    }
    @RequestMapping("/deleteUserBehavior")
    public ResultVO<Integer> deleteUserBehavior(@RequestParam("id")Integer id){
        userBehaviorService.deleteUserBehavior(id);
        return success(200, "删除用户行为成功", 1);
    }
    @PostMapping("/updateUserBehaviorByCreateTime")
    public ResultVO<Integer> updateUserBehaviorByCreateTime(@RequestParam("createTime")LocalDateTime createTime, @RequestParam("id")Integer id){
        userBehaviorService.updateUserBehaviorByCreateTime(createTime, id);
        return success(200, "更新用户行为成功", 1);
    }
}
